//
//  ComplainTableView.m
//  wtshoppingcite
//
//  Created by TW on 15-1-17.
//  Copyright (c) 2015年 TW. All rights reserved.
//

#import "ComplainTableView.h"
#import "ComplaintDetailHeaderCell.h"
#import "ComplaintProcessCell.h"

@implementation ComplainTableView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}

- (id)initWithFrame:(CGRect)frame style:(UITableViewStyle)style
{
    self = [super initWithFrame:frame style:style];
    if(self){
        self.backgroundView = nil;
        self.backgroundColor = [UIColor whiteColor];
        self.dataSource = self;
        self.delegate = self;
        self.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
    }
    return self;
}



- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if(section == 0){
        return 1;
    }else if(section  == 1){
        return _status.intValue+1;
    }
    return 0;
}

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    switch (indexPath.section) {
        case 0:
        {
            static NSString* CellIdentifier = @"cell";
            
            ComplaintDetailHeaderCell* cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
            if(cell == nil)
            {
                cell = [[ComplaintDetailHeaderCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
            }
            cell.data = _infoData[@"header"];
            return cell;
        }break;
        case 1:{
            static NSString* CellIdentifier = @"cell";
            
            ComplaintProcessCell* cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
            if(cell == nil)
            {
                cell = [[ComplaintProcessCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
            }
            cell.data = [_infoData[@"list"] objectAtIndex:indexPath.row];
            return cell;
        }break;
        default:
            break;
    }
    return nil;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    switch (indexPath.section) {
        case 0:
        {
            if(_status.intValue == 2){
                return 300+60;
            }else{
                return 150+60;
            }
        }break;
        case 1:{
            
            return 100;
        }break;
        default:
            break;
    }
    return 0;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 20;
}

-(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView* view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 30)];
    view.backgroundColor = COLOR_RGB(238, 238, 238);
    
    UILabel* label = [self createLabelWithFrame:CGRectMake(15, -5, SCREEN_WIDTH, 30) text:@"aaa" font:15 textAli:NSTextAlignmentLeft textColor:MAIN_GRAY_COLOR];
    [view addSubview:label];
    
    if(section == 0){
        NSDictionary* dic = _infoData[@"header"];
        NSString* code = [NSString stringWithFormat:@"单号:%@",dic[@"code"]];
        label.text = ObjToString(code);
    }else{
        label.text = @"报修受理进程";
    }
    return view;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(self.eventsDelegate!= nil  && [self.eventsDelegate respondsToSelector:@selector(basetableView:didSelectRowAtIndexPath:)]){
        [self.eventsDelegate basetableView:self didSelectRowAtIndexPath:indexPath];
    }
    
}


-(UILabel*)createLabelWithFrame:(CGRect)frame text:(NSString*)text font:(int)font textAli:(NSTextAlignment)alig textColor:(UIColor*)tc{
    if(text == nil)
        text = @"";
    UILabel* label = [[UILabel alloc] initWithFrame:frame];
    label.text = text;
    label.font = [UIFont systemFontOfSize:font];
    label.textAlignment = alig;
    label.textColor = tc;
    label.backgroundColor = [UIColor clearColor];
    return label;
}



@end
